home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / misc / execports / waitport.s < prev   
Text File  |  1992-09-02  |  4KB  |  162 lines

  1. ;==============================================================[ Description ]=
  2.  
  3. ;    This is an example of a source, which waits for message from other
  4. ;    task. You will have to run this file first, then another called PutMsg.
  5. ;    This routine reads the message and prints texts, that you have typed
  6. ;    after PutMsg program as arguments.
  7.  
  8. ;    $VER: WaitPort.s V1.1 (30.10.94)
  9. ;    Source by Cromax of Alchemy (kita@sun10.ci.pwr.wroc.pl)
  10.  
  11. ;===================================================================[ Values ]=
  12.  
  13. ExecBase        Equ    4
  14.  
  15. _LVOForbid        Equ    -132
  16. _LVOPermit        Equ    -138
  17. _LVOFindTask        Equ    -294
  18. _LVOAddPort        Equ    -354
  19. _LVORemPort        Equ    -360
  20. _LVOGetMsg        Equ    -372
  21. _LVOReplyMsg        Equ    -378
  22. _LVOWaitPort        Equ    -384
  23. _LVOCloseLibrary    Equ    -414
  24. _LVOOpenLibrary        Equ    -552
  25.  
  26. _LVOWrite        Equ    -048
  27. _LVOOutput        Equ    -060
  28.  
  29. NT_MSGPORT        Equ    4
  30.  
  31. lh_TailPred        Equ    008
  32.  
  33. mp_SigTask        Equ    016
  34. mp_MsgList        Equ    020
  35.  
  36. mymsg_Length        Equ    4        ; Offsets of our message
  37. mymsg_String        Equ    8        ; defined by myself
  38.  
  39. DOSVersion        Equ    33        ; KickStart 1.2+
  40.  
  41. ;=============================================================[ Main Program ]=
  42.  
  43.         Section    NewPort,Code_P
  44.  
  45. Begin:        bra.s    .Skip
  46.  
  47.         dc.b    "$VER: WaitPort V1.1 (30.10.94)",10,0
  48.         even
  49.  
  50. .Skip:        movea.l    [ExecBase].w,a6
  51.         lea    DOSName,a1
  52.         moveq    #DOSVersion,d0
  53.         jsr    _LVOOpenLibrary(a6)
  54.         move.l    d0,_DOSBase        ; Can not open DOS library?
  55.         beq.w    CloseDown        ; Then quit!
  56.  
  57.         movea.l    [ExecBase].w,a6
  58.         jsr    _LVOForbid(a6)
  59.  
  60.         movea.l    [ExecBase].w,a6        ; Find pointer to Task
  61.         suba.l    a1,a1            ; structure of our task
  62.         jsr    _LVOFindTask(a6)    ; (if a1=NULL)
  63.         move.l    d0,_Task
  64.  
  65.         movea.l    [ExecBase].w,a6
  66.         jsr    _LVOPermit(a6)
  67.  
  68.         lea    MsgPort,a0        ; Complete MsgPort structure
  69.         move.l    _Task,mp_SigTask(a0)    ; If we didn't found anything
  70.         beq.w    CloseDown        ; then quit (rather impossible)
  71.         adda.l    #mp_MsgList,a0        ; Set pointers of List struct
  72.         move.l    a0,lh_TailPred(a0)    ; in MsgPort structure
  73.         addq    #4,a0            ; Get addres of lh_Tail
  74.         clr.l    (a0)            ; Clear lh_Tail
  75.         move.l    a0,-(a0)        ; Address of lh_Tail to lh_Head
  76.  
  77.         movea.l    [ExecBase].w,a6        ; Add these lines, if you want
  78.         lea    MsgPort,a1        ; your port to be public (to
  79.         jsr    _LVOAddPort(a6)        ; add it to system's port list)
  80.  
  81. .Wait:        movea.l    [ExecBase].w,a6        ; Wait for message...
  82.         lea    MsgPort,a0
  83.         jsr    _LVOWaitPort(a6)
  84.  
  85.         movea.l    [ExecBase].w,a6
  86.         lea    MsgPort,a0
  87.         jsr    _LVOGetMsg(a6)        ; In d0 we have pointer to
  88.         move.l    d0,_Message        ; Message structure
  89.  
  90.         move.l    d0,a0
  91.         adda.l    #20,a0
  92.         move.l    a0,_OurMessage        ; In a0 pointer to our message
  93.         
  94.         cmpi.l    #"CRMX",(a0)        ; Compare ID Header...
  95.         bne.s    .Wait            ; Naw, it's some crap...
  96.  
  97.         movea.l    _DOSBase,a6
  98.         jsr    _LVOOutput(a6)
  99.         tst.l    d0
  100.         beq.s    ReplyMessage        ; No output for text to write
  101.  
  102.         movea.l    _DOSBase,a6
  103.         move.l    d0,d1
  104.         movea.l    _OurMessage,a0
  105.         move.l    mymsg_String(a0),d2
  106.         move.l    mymsg_Length(a0),d3
  107.         cmpi.l    #1,d3
  108.         beq.s    ReplyMessage
  109.         jsr    _LVOWrite(a6)        ; Write string we've received
  110.  
  111. ReplyMessage:    movea.l    [ExecBase].w,a6
  112.         movea.l    _Message,a1
  113.         jsr    _LVOReplyMsg(a6)
  114.  
  115. CloseDown:    nop                ; Close everything down...
  116.  
  117. .RemPort:    tst.l    _Task
  118.         beq.s    .End
  119.         movea.l    [ExecBase].w,a6        ; Add these lines, if your
  120.         lea    MsgPort,a1        ; port was public (to remove
  121.         jsr    _LVORemPort(a6)        ; it from port list)
  122.  
  123. .CloseDOS:    tst.l    _DOSBase
  124.         beq.s    .End
  125.         movea.l    [ExecBase].w,a6
  126.         movea.l    _DOSBase,a1
  127.         jsr    _LVOCloseLibrary(a6)
  128.  
  129. .End:        moveq    #0,d0
  130.         rts
  131.  
  132. ;=====================================================================[ Data ]=
  133.  
  134.         Section    Data,Data_P
  135.  
  136. MsgPort:    dc.l    0        ; ln_Succ
  137.         dc.l    0        ; ln_Pred
  138.         dc.b    NT_MSGPORT    ; ln_Type
  139.         dc.b    0        ; ln_Pri
  140.         dc.l    PortName    ; ln_Name
  141.         dc.b    0        ; mp_Flags
  142.         dc.b    0        ; mp_SigBits
  143.         dc.l    0        ; mp_SigTask
  144.         dc.l    0        ; lh_Head
  145.         dc.l    0        ; lh_Tail
  146.         dc.l    0        ; lh_TailPred
  147.         dc.b    0        ; lh_Type
  148.         dc.b    0        ; lh_pad
  149.  
  150. DOSName:    dc.b    "dos.library",0
  151. PortName:    dc.b    "Amsterdam",0
  152.  
  153. ;=====================================================================[ Vars ]=
  154.  
  155.         Section    Vars,Bss
  156.  
  157. _DOSBase:    ds.l    1
  158. _Task:        ds.l    1
  159. _Message:    ds.l    1
  160. _OurMessage:    ds.l    1
  161.  
  162.